home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / GAS211S2.ZIP / src / gas-211 / include / aout / aout64.h < prev    next >
C/C++ Source or Header  |  1993-05-30  |  14KB  |  381 lines

  1. /* `a.out' object-file definitions, including extensions to 64-bit fields */
  2.  
  3. #ifndef __A_OUT_64_H__
  4. #define __A_OUT_64_H__
  5.  
  6. /* This is the layout on disk of the 32-bit or 64-bit exec header. */
  7.  
  8. #ifndef external_exec
  9. struct external_exec 
  10. {
  11.   bfd_byte e_info[4];        /* magic number and stuff        */
  12.   bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes    */
  13.   bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes    */
  14.   bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes         */
  15.   bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes     */
  16.   bfd_byte e_entry[BYTES_IN_WORD]; /* start address             */
  17.   bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info    */
  18.   bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info     */
  19. };
  20.  
  21. #define    EXEC_BYTES_SIZE    (4 + BYTES_IN_WORD * 7)
  22.  
  23. /* Magic numbers for a.out files */
  24.  
  25. #if ARCH_SIZE==64
  26. #define OMAGIC 0x1001        /* Code indicating object file  */
  27. #define ZMAGIC 0x1002        /* Code indicating demand-paged executable.  */
  28. #define NMAGIC 0x1003        /* Code indicating pure executable.  */
  29. #else
  30. #define OMAGIC 0407        /* ...object file or impure executable.  */
  31. #define NMAGIC 0410        /* Code indicating pure executable.  */
  32. #define ZMAGIC 0413        /* Code indicating demand-paged executable.  */
  33. #endif
  34.  
  35. #define N_BADMAG(x)      (N_MAGIC(x) != OMAGIC        \
  36.             && N_MAGIC(x) != NMAGIC        \
  37.               && N_MAGIC(x) != ZMAGIC)
  38. #endif
  39.  
  40. /* By default, segment size is constant.  But some machines override this
  41.    to be a function of the a.out header (e.g. machine type).  */
  42. #ifndef    N_SEGSIZE
  43. #define    N_SEGSIZE(x)    SEGMENT_SIZE
  44. #endif
  45.  
  46. /* Virtual memory address of the text section.
  47.    This is getting very complicated.  A good reason to discard a.out format
  48.    for something that specifies these fields explicitly.  But til then...
  49.  
  50.    * OMAGIC and NMAGIC files:
  51.        (object files: text for "relocatable addr 0" right after the header)
  52.        start at 0, offset is EXEC_BYTES_SIZE, size as stated.
  53.    * The text address, offset, and size of ZMAGIC files depend
  54.      on the entry point of the file:
  55.      * entry point below TEXT_START_ADDR:
  56.        (hack for SunOS shared libraries)
  57.        start at 0, offset is 0, size as stated.
  58.      * If N_HEADER_IN_TEXT(x) is true (which defaults to being the
  59.        case when the entry point is EXEC_BYTES_SIZE or further into a page):
  60.        no padding is needed; text can start after exec header.  Sun
  61.        considers the text segment of such files to include the exec header;
  62.        for BFD's purposes, we don't, which makes more work for us.
  63.        start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE,
  64.        size as stated minus EXEC_BYTES_SIZE.
  65.      * If N_HEADER_IN_TEXT(x) is false (which defaults to being the case when
  66.        the entry point is less than EXEC_BYTES_SIZE into a page (e.g. page
  67.        aligned)): (padding is needed so that text can start at a page boundary)
  68.        start at TEXT_START_ADDR, offset PAGE_SIZE, size as stated.
  69.  
  70.     Specific configurations may want to hardwire N_HEADER_IN_TEXT,
  71.     for efficiency or to allow people to play games with the entry point.
  72.     In that case, you would #define N_HEADER_IN_TEXT(x) as 1 for sunos,
  73.     and as 0 for most other hosts (Sony News, Vax Ultrix, etc).
  74.     (Do this in the appropriate bfd target file.)
  75.     (The default is a heuristic that will break if people try changing
  76.     the entry point, perhaps with the ld -e flag.)
  77.     */
  78.  
  79. #ifndef N_HEADER_IN_TEXT
  80. #define N_HEADER_IN_TEXT(x) (((x).a_entry & (PAGE_SIZE-1)) >= EXEC_BYTES_SIZE)
  81. #endif
  82.  
  83. #ifndef N_SHARED_LIB
  84. #define N_SHARED_LIB(x) ((x).a_entry < TEXT_START_ADDR)
  85. #endif
  86.  
  87. #ifndef N_TXTADDR
  88. #define N_TXTADDR(x) \
  89.     (N_MAGIC(x) != ZMAGIC ? 0 :    /* object file or NMAGIC */\
  90.      N_SHARED_LIB(x) ? 0 :    \
  91.      N_HEADER_IN_TEXT(x)  ?    \
  92.         TEXT_START_ADDR + EXEC_BYTES_SIZE :    /* no padding */\
  93.         TEXT_START_ADDR            /* a page of padding */\
  94.     )
  95. #endif
  96.  
  97. /* Offset in an a.out of the start of the text section. */
  98. #ifndef N_TXTOFF
  99. #define N_TXTOFF(x)    \
  100.     (N_MAGIC(x) != ZMAGIC ? EXEC_BYTES_SIZE : /* object file or NMAGIC */\
  101.      N_SHARED_LIB(x) ? 0 : \
  102.      N_HEADER_IN_TEXT(x) ?    \
  103.         EXEC_BYTES_SIZE :            /* no padding */\
  104.         PAGE_SIZE                /* a page of padding */\
  105.     )
  106. #endif
  107. /* Size of the text section.  It's always as stated, except that we
  108.    offset it to `undo' the adjustment to N_TXTADDR and N_TXTOFF
  109.    for ZMAGIC files that nominally include the exec header
  110.    as part of the first page of text.  (BFD doesn't consider the
  111.    exec header to be part of the text segment.)  */
  112. #ifndef N_TXTSIZE
  113. #define    N_TXTSIZE(x) \
  114.     ((N_MAGIC(x) != ZMAGIC || N_SHARED_LIB(x)) ? (x).a_text : \
  115.      N_HEADER_IN_TEXT(x)  ?    \
  116.         (x).a_text - EXEC_BYTES_SIZE:    /* no padding */\
  117.         (x).a_text                /* a page of padding */\
  118.     )
  119. #endif
  120. /* The address of the data segment in virtual memory.
  121.    It is the text segment address, plus text segment size, rounded
  122.    up to a N_SEGSIZE boundary for pure or pageable files. */
  123. #ifndef N_DATADDR
  124. #define N_DATADDR(x) \
  125.     (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+N_TXTSIZE(x)) \
  126.      :  (N_SEGSIZE(x) + ((N_TXTADDR(x)+N_TXTSIZE(x)-1) & ~(N_SEGSIZE(x)-1))))
  127. #endif
  128. /* The address of the BSS segment -- immediately after the data segment.  */
  129.  
  130. #define N_BSSADDR(x)    (N_DATADDR(x) + (x).a_data)
  131.  
  132. /* Offsets of the various portions of the file after the text segment.  */
  133.  
  134. #ifndef N_DATOFF
  135. #define N_DATOFF(x)    ( N_TXTOFF(x) + N_TXTSIZE(x) )
  136. #endif
  137. #ifndef N_TRELOFF
  138. #define N_TRELOFF(x)    ( N_DATOFF(x) + (x).a_data )
  139. #endif
  140. #ifndef N_DRELOFF
  141. #define N_DRELOFF(x)    ( N_TRELOFF(x) + (x).a_trsize )
  142. #endif
  143. #ifndef N_SYMOFF
  144. #define N_SYMOFF(x)    ( N_DRELOFF(x) + (x).a_drsize )
  145. #endif
  146. #ifndef N_STROFF
  147. #define N_STROFF(x)    ( N_SYMOFF(x) + (x).a_syms )
  148. #endif
  149.  
  150. /* Symbols */
  151. #ifndef external_nlist
  152. struct external_nlist {
  153.   bfd_byte e_strx[BYTES_IN_WORD];    /* index into string table of name */
  154.   bfd_byte e_type[1];            /* type of symbol */
  155.   bfd_byte e_other[1];            /* misc info (usually empty) */
  156.   bfd_byte e_desc[2];            /* description field */
  157.   bfd_byte e_value[BYTES_IN_WORD];    /* value of symbol */
  158. };
  159. #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
  160. #endif
  161.  
  162. struct internal_nlist {
  163.   unsigned long n_strx;            /* index into string table of name */
  164.   unsigned char n_type;            /* type of symbol */
  165.   unsigned char n_other;        /* misc info (usually empty) */
  166.   unsigned short n_desc;        /* description field */
  167.   bfd_vma n_value;            /* value of symbol */
  168. };
  169.  
  170. /* The n_type field is the symbol type, containing:  */
  171.  
  172. #define N_UNDF    0    /* Undefined symbol */
  173. #define N_ABS     2    /* Absolute symbol -- defined at particular addr */
  174. #define N_TEXT     4    /* Text sym -- defined at offset in text seg */
  175. #define N_DATA     6    /* Data sym -- defined at offset in data seg */
  176. #define N_BSS     8    /* BSS  sym -- defined at offset in zero'd seg */
  177. #define    N_COMM    0x12    /* Common symbol (visible after shared lib dynlink) */
  178. #define N_FN    0x1f    /* File name of .o file */
  179. #define    N_FN_SEQ 0x0C    /* N_FN from Sequent compilers (sigh) */
  180. /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
  181.    N_DATA, or N_BSS.  When the low-order bit of other types is set,
  182.    (e.g. N_WARNING versus N_FN), they are two different types.  */
  183. #define N_EXT     1    /* External symbol (as opposed to local-to-this-file) */
  184. #define N_TYPE  0x1e
  185. #define N_STAB     0xe0    /* If any of these bits are on, it's a debug symbol */
  186.  
  187. #define N_INDR 0x0a
  188.  
  189. /* The following symbols refer to set elements.
  190.    All the N_SET[ATDB] symbols with the same name form one set.
  191.    Space is allocated for the set in the text section, and each set
  192.    elements value is stored into one word of the space.
  193.    The first word of the space is the length of the set (number of elements).
  194.  
  195.    The address of the set is made into an N_SETV symbol
  196.    whose name is the same as the name of the set.
  197.    This symbol acts like a N_DATA global symbol
  198.    in that it can satisfy undefined external references.  */
  199.  
  200. /* These appear as input to LD, in a .o file.  */
  201. #define    N_SETA    0x14        /* Absolute set element symbol */
  202. #define    N_SETT    0x16        /* Text set element symbol */
  203. #define    N_SETD    0x18        /* Data set element symbol */
  204. #define    N_SETB    0x1A        /* Bss set element symbol */
  205.  
  206. /* This is output from LD.  */
  207. #define N_SETV    0x1C        /* Pointer to set vector in data area.  */
  208.  
  209. /* Warning symbol. The text gives a warning message, the next symbol
  210.    in the table will be undefined. When the symbol is referenced, the
  211.    message is printed.  */
  212.  
  213. #define    N_WARNING 0x1e
  214.  
  215. /* Relocations 
  216.  
  217.   There    are two types of relocation flavours for a.out systems,
  218.   standard and extended. The standard form is used on systems where the
  219.   instruction has room for all the bits of an offset to the operand, whilst
  220.   the extended form is used when an address operand has to be split over n
  221.   instructions. Eg, on the 68k, each move instruction can reference
  222.   the target with a displacement of 16 or 32 bits. On the sparc, move
  223.   instructions use an offset of 14 bits, so the offset is stored in
  224.   the reloc field, and the data in the section is ignored.
  225. */
  226.  
  227. /* This structure describes a single relocation to be performed.
  228.    The text-relocation section of the file is a vector of these structures,
  229.    all of which apply to the text section.
  230.    Likewise, the data-relocation section applies to the data section.  */
  231.  
  232. struct reloc_std_external {
  233.   bfd_byte    r_address[BYTES_IN_WORD];    /* offset of of data to relocate     */
  234.   bfd_byte r_index[3];    /* symbol table index of symbol     */
  235.   bfd_byte r_type[1];    /* relocation type            */
  236. };
  237.  
  238. #define    RELOC_STD_BITS_PCREL_BIG    0x80
  239. #define    RELOC_STD_BITS_PCREL_LITTLE    0x01
  240.  
  241. #define    RELOC_STD_BITS_LENGTH_BIG    0x60
  242. #define    RELOC_STD_BITS_LENGTH_SH_BIG    5    /* To shift to units place */
  243. #define    RELOC_STD_BITS_LENGTH_LITTLE    0x06
  244. #define    RELOC_STD_BITS_LENGTH_SH_LITTLE    1
  245.  
  246. #define    RELOC_STD_BITS_EXTERN_BIG    0x10
  247. #define    RELOC_STD_BITS_EXTERN_LITTLE    0x08
  248.  
  249. #define    RELOC_STD_BITS_BASEREL_BIG    0x08
  250. #define    RELOC_STD_BITS_BASEREL_LITTLE    0x08
  251.  
  252. #define    RELOC_STD_BITS_JMPTABLE_BIG    0x04
  253. #define    RELOC_STD_BITS_JMPTABLE_LITTLE    0x04
  254.  
  255. #define    RELOC_STD_BITS_RELATIVE_BIG    0x02
  256. #define    RELOC_STD_BITS_RELATIVE_LITTLE    0x02
  257.  
  258. #define    RELOC_STD_SIZE    (BYTES_IN_WORD + 3 + 1)        /* Bytes per relocation entry */
  259.  
  260. struct reloc_std_internal
  261. {
  262.   bfd_vma r_address;        /* Address (within segment) to be relocated.  */
  263.   /* The meaning of r_symbolnum depends on r_extern.  */
  264.   unsigned int r_symbolnum:24;
  265.   /* Nonzero means value is a pc-relative offset
  266.      and it should be relocated for changes in its own address
  267.      as well as for changes in the symbol or section specified.  */
  268.   unsigned int r_pcrel:1;
  269.   /* Length (as exponent of 2) of the field to be relocated.
  270.      Thus, a value of 2 indicates 1<<2 bytes.  */
  271.   unsigned int r_length:2;
  272.   /* 1 => relocate with value of symbol.
  273.      r_symbolnum is the index of the symbol
  274.      in files the symbol table.
  275.      0 => relocate with the address of a segment.
  276.      r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
  277.      (the N_EXT bit may be set also, but signifies nothing).  */
  278.   unsigned int r_extern:1;
  279.   /* The next three bits are for SunOS shared libraries, and seem to
  280.      be undocumented.  */
  281.   unsigned int r_baserel:1;    /* Linkage table relative */
  282.   unsigned int r_jmptable:1;    /* pc-relative to jump table */
  283.   unsigned int r_relative:1;    /* "relative relocation" */
  284.   /* unused */
  285.   unsigned int r_pad:1;        /* Padding -- set to zero */
  286. };
  287.  
  288.  
  289. /* EXTENDED RELOCS  */
  290.  
  291. struct reloc_ext_external {
  292.   bfd_byte r_address[BYTES_IN_WORD];    /* offset of of data to relocate     */
  293.   bfd_byte r_index[3];    /* symbol table index of symbol     */
  294.   bfd_byte r_type[1];    /* relocation type            */
  295.   bfd_byte r_addend[BYTES_IN_WORD];    /* datum addend                */
  296. };
  297.  
  298. #define    RELOC_EXT_BITS_EXTERN_BIG    0x80
  299. #define    RELOC_EXT_BITS_EXTERN_LITTLE    0x01
  300.  
  301. #define    RELOC_EXT_BITS_TYPE_BIG        0x1F
  302. #define    RELOC_EXT_BITS_TYPE_SH_BIG    0
  303. #define    RELOC_EXT_BITS_TYPE_LITTLE    0xF8
  304. #define    RELOC_EXT_BITS_TYPE_SH_LITTLE    3
  305.  
  306. /* Bytes per relocation entry */
  307. #define    RELOC_EXT_SIZE    (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
  308.  
  309. enum reloc_type
  310. {
  311.   /* simple relocations */
  312.   RELOC_8,            /* data[0:7] = addend + sv         */
  313.   RELOC_16,            /* data[0:15] = addend + sv         */
  314.   RELOC_32,            /* data[0:31] = addend + sv         */
  315.   /* pc-rel displacement */
  316.   RELOC_DISP8,            /* data[0:7] = addend - pc + sv     */
  317.   RELOC_DISP16,            /* data[0:15] = addend - pc + sv     */
  318.   RELOC_DISP32,            /* data[0:31] = addend - pc + sv     */
  319.   /* Special */
  320.   RELOC_WDISP30,        /* data[0:29] = (addend + sv - pc)>>2     */
  321.   RELOC_WDISP22,        /* data[0:21] = (addend + sv - pc)>>2     */
  322.   RELOC_HI22,            /* data[0:21] = (addend + sv)>>10     */
  323.   RELOC_22,            /* data[0:21] = (addend + sv)         */
  324.   RELOC_13,            /* data[0:12] = (addend + sv)        */
  325.   RELOC_LO10,            /* data[0:9] = (addend + sv)        */
  326.   RELOC_SFA_BASE,        
  327.   RELOC_SFA_OFF13,
  328.   /* P.I.C. (base-relative) */
  329.   RELOC_BASE10,          /* Not sure - maybe we can do this the */
  330.   RELOC_BASE13,            /* right way now */
  331.   RELOC_BASE22,
  332.   /* for some sort of pc-rel P.I.C. (?) */
  333.   RELOC_PC10,
  334.   RELOC_PC22,
  335.   /* P.I.C. jump table */
  336.   RELOC_JMP_TBL,
  337.   /* reputedly for shared libraries somehow */
  338.   RELOC_SEGOFF16,
  339.   RELOC_GLOB_DAT,
  340.   RELOC_JMP_SLOT,
  341.   RELOC_RELATIVE,
  342.  
  343.   RELOC_11,    
  344.   RELOC_WDISP2_14,
  345.   RELOC_WDISP19,
  346.   RELOC_HHI22,            /* data[0:21] = (addend + sv) >> 42     */
  347.   RELOC_HLO10,            /* data[0:9] = (addend + sv) >> 32      */
  348.   
  349.   /* 29K relocation types */
  350.   RELOC_JUMPTARG,
  351.   RELOC_CONST,
  352.   RELOC_CONSTH,
  353.   
  354.  
  355.   /* Q .
  356.      What are the other ones,
  357.      Since this is a clean slate, can we throw away the ones we dont
  358.      understand ? Should we sort the values ? What about using a
  359.      microcode format like the 68k ?
  360.      */
  361.   NO_RELOC
  362.   };
  363.  
  364.  
  365. struct reloc_internal {
  366.   bfd_vma r_address;        /* offset of of data to relocate     */
  367.   long    r_index;        /* symbol table index of symbol     */
  368.   enum reloc_type r_type;    /* relocation type            */
  369.   bfd_vma r_addend;        /* datum addend                */
  370. };
  371.  
  372. /* Q.
  373.    Should the length of the string table be 4 bytes or 8 bytes ?
  374.  
  375.    Q.
  376.    What about archive indexes ?
  377.  
  378.  */
  379.  
  380. #endif                /* __A_OUT_64_H__ */
  381.